package com.doublefish.doublefishrobot.ui.home.bean;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.doublefish.doublefishrobot.R;
import com.doublefish.doublefishrobot.utils.AppCacheUtil;
import com.doublefish.doublefishrobot.utils.LocalizationUtils;
import com.doublefish.doublefishrobot.utils.ble.bean.ModeConstant;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
 * 作者:dugaofeng on 2024/10/18 16:21
 */
public class ModeSettingBean implements Parcelable {

    private int t_id;  //数据库的id

    private int difficulty;  //难度
    private String name;      //用于显示的名称
    private String name_en;   //英文名
    private String name_zh;   //中文名
    private int mode;     //数字编号

    //协议的类型，根据模型返回值来确定 0.未知  1.超8的协议  ModeConstant.ProtocolTypeS8  2.双鱼自研（目前用于超6）ModeConstant.ProtocolTypeS6  3.超5  ModeConstant.ProtocolTypeS5
    private int protocolType;

    // 根据脚本生成 steps模型
    private String script;
    private List<ModeSettingStepBean> steps;


    public ModeSettingBean() {

    }

    public int getTid() {
        return t_id;
    }

    public void setTid(int t_id) {
        this.t_id = t_id;
    }

    public int getDifficulty() {
        return difficulty;
    }

    public void setDifficulty(int difficulty) {
        this.difficulty = difficulty;
    }

    //    model: 设备类型 int  1.超8  2.超6  3.超5 4.超3
    public void setModel(int model) {
        if (model == 4) {
            //设别类型转化为 协议类型
            model = 3;
        }
        this.protocolType = model;
    }

//    public String getName() {
//        return name;
//    }

    public String getName() {
        if (TextUtils.isEmpty(name)) {
            return LocalizationUtils.getInstance().isEn() ? name_en : name_zh;
        }
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName_en() {
        return name_en;
    }

    public void setName_en(String name_en) {
        this.name_en = name_en;
    }

    public String getName_zh() {
        return name_zh;
    }

    public void setName_zh(String name_zh) {
        this.name_zh = name_zh;
    }

    public int getMode() {
        return mode;
    }

    public void setMode(int mode) {
        this.mode = mode;
    }

    // 根据mode生成code
    public String getCode() {
        if (difficulty == 0 || difficulty >= 5) {
            return null;
        }
        String formatStr = "%02dR02";
        String code = String.format(Locale.getDefault(), formatStr, mode);
        return code;
    }

    public String getDifficultyName() {
        Context context = AppCacheUtil.getInstance().getAppContext();
        if (difficulty == 0) {
            return context.getString(R.string.basic_mode);
        }
        if (difficulty == 1) {
            return context.getString(R.string.rudimental);
        }
        if (difficulty == 2) {
            return context.getString(R.string.junior);
        }
        if (difficulty == 3) {
            return context.getString(R.string.intermediate);
        }
        if (difficulty == 4) {
            return context.getString(R.string.senior);
        }
        return null;
    }

    //脚本中 是否存在超过了2个范围值的配置项
    public boolean isMoreThan2Range() {
        //fixme 只判断2 - 9 更多的暂时不用判断了
        return script.contains("#2,")
                || script.contains("#3,")
                || script.contains("#4,")
                || script.contains("#5,")
                || script.contains("#6,")
                || script.contains("#7,")
                || script.contains("#8,")
                || script.contains("#9,");
    }

    public String getScript() {
        return script;
    }

    public void setScript(String script) {
        this.script = script;
    }

    public void setProtocolType(int protocolType) {
        this.protocolType = protocolType;
    }

    public int getProtocolType() {
        return protocolType;
    }

    // 根据脚本生成 steps模型
    public List<ModeSettingStepBean> getSteps() {
        if (steps != null && steps.size() != 0) {
            return steps;
        }

        if (script == null || script.length() == 0) {
            return null;
        }
        //将脚本进行分割， 分割成多条独立的发球将脚本
        String[] stepScriptArr = splitScript(script);
        if (stepScriptArr == null || stepScriptArr.length == 0) {
            return null;
        }

        steps = new ArrayList<>();
        for (int i = 0; i < stepScriptArr.length; i++) {
            String stepScript = stepScriptArr[i];
            if (stepScript.length() == 0) {
                continue;
            }
            //根据脚本生成模型
            ModeSettingStepBean stepBean = ModeSettingStepBean.createSettingStepBean(stepScript, protocolType);
            steps.add(stepBean);
        }
        return steps;
    }

    private String[] splitScript(String script) {
        if (script == null || script.length() == 0) {
            return null;
        }
        if (protocolType == ModeConstant.ProtocolTypeS5) {
            return script.split("#");
        }
        return script.split("#\n");
    }

    //mark 生成发球脚本
    public String makeScript() {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < getSteps().size(); i++) {
            ModeSettingStepBean stepBean = getSteps().get(i);
            String itemScript = stepBean.makeScript();
            stringBuilder.append(itemScript);
        }
        return stringBuilder.toString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.protocolType);
        dest.writeInt(this.difficulty);
        dest.writeString(this.name);
        dest.writeString(this.name_en);
        dest.writeString(this.name_zh);
        dest.writeInt(this.mode);
        dest.writeString(this.script);

        // FIXME: 2025/4/11   steps不写入，每次从script生成？？？？
//        dest.writeList(this.steps);
    }

    public void readFromParcel(Parcel source) {
        this.protocolType = source.readInt();
        this.difficulty = source.readInt();
        this.name = source.readString();
        this.name_en = source.readString();
        this.name_zh = source.readString();
        this.mode = source.readInt();
        this.script = source.readString();
//        this.steps = new ArrayList<ModeSettingStepBean>();
//        source.readList(this.steps, ModeSettingStepBean.class.getClassLoader());
    }

    protected ModeSettingBean(Parcel in) {
        this.protocolType = in.readInt();
        this.difficulty = in.readInt();
        this.name = in.readString();
        this.name_en = in.readString();
        this.name_zh = in.readString();
        this.mode = in.readInt();
        this.script = in.readString();
//        this.steps = new ArrayList<ModeSettingStepBean>();
//        in.readList(this.steps, ModeSettingStepBean.class.getClassLoader());
    }

    public static final Parcelable.Creator<ModeSettingBean> CREATOR = new Parcelable.Creator<ModeSettingBean>() {
        @Override
        public ModeSettingBean createFromParcel(Parcel source) {
            return new ModeSettingBean(source);
        }

        @Override
        public ModeSettingBean[] newArray(int size) {
            return new ModeSettingBean[size];
        }
    };


    //region ModeSettingLoopBean
    public static class ModeSettingLoopBean implements Parcelable {
        private int protocolType; //协议的类型，根据模型返回值来确定 0.未知  1.超8的协议  2.双鱼自研（目前用于超6）

        int loopType;   //0.训练循环次数  1.训练时长
        private ModeSettingItemBean loopCountItemBean;    //训练循环次数
        private ModeSettingItemBean loopTimeItemBean;     //训练时长
        private ModeSettingItemBean loopIntervalItemBean; //训练循环间隔

        public static ModeSettingLoopBean defaultLoop(int protocolType) {
            Context context = AppCacheUtil.getInstance().getAppContext();
            //初始化loop
            ModeSettingLoopBean loop = new ModeSettingLoopBean();
            loop.loopType = 0;

            int minValue = 1;
            int maxValue = 200;
            if (protocolType == ModeConstant.ProtocolTypeS8) {
                minValue = 1;
                maxValue = 200;
            } else {
                minValue = 1;
                maxValue = 100;
            }
            ModeSettingItemBean loopCountItemBean = new ModeSettingItemBean(context.getString(R.string.cycle_index), false, false, maxValue, minValue, 1, 0, 0);
            loopCountItemBean.setProtocolType(protocolType);

            minValue = 1;
            maxValue = 1440;
            if (protocolType == ModeConstant.ProtocolTypeS8) {
                minValue = 1;
                maxValue = 1440;
            } else {
                minValue = 1;
                maxValue = 120;
            }
            ModeSettingItemBean loopTimeItemBean = new ModeSettingItemBean(context.getString(R.string.cycle_time), false, false, maxValue, minValue, 1, 0, 0);
            loopTimeItemBean.setProtocolType(protocolType);

            minValue = 1;
            maxValue = 20;
            int loopInterval = 3;
            if (protocolType == ModeConstant.ProtocolTypeS8) {
                minValue = 1;
                maxValue = 20;
                loopInterval = 3;
            } else {
                minValue = 1;
                maxValue = 10;
                loopInterval = 1;
            }
            ModeSettingItemBean loopIntervalItemBean = new ModeSettingItemBean(context.getString(R.string.cycle_interval), false, false, maxValue, minValue, loopInterval, 0, 0);
            loopIntervalItemBean.setProtocolType(protocolType);

            loop.loopCountItemBean = loopCountItemBean;
            loop.loopTimeItemBean = loopTimeItemBean;
            loop.loopIntervalItemBean = loopIntervalItemBean;

            return loop;
        }

        public int getLoopType() {
            return loopType;
        }

        public void setLoopType(int loopType) {
            this.loopType = loopType;
        }

        public ModeSettingItemBean getLoopCountItemBean() {
            return loopCountItemBean;
        }

        public void setLoopCountItemBean(ModeSettingItemBean loopCountItemBean) {
            this.loopCountItemBean = loopCountItemBean;
        }

        public ModeSettingItemBean getLoopTimeItemBean() {
            return loopTimeItemBean;
        }

        public void setLoopTimeItemBean(ModeSettingItemBean loopTimeItemBean) {
            this.loopTimeItemBean = loopTimeItemBean;
        }

        public ModeSettingItemBean getLoopIntervalItemBean() {
            return loopIntervalItemBean;
        }

        public void setLoopIntervalItemBean(ModeSettingItemBean loopIntervalItemBean) {
            this.loopIntervalItemBean = loopIntervalItemBean;
        }

        public int getProtocolType() {
            return protocolType;
        }

        public void setProtocolType(int protocolType) {
            this.protocolType = protocolType;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(this.protocolType);
            dest.writeInt(this.loopType);
            dest.writeParcelable(this.loopCountItemBean, flags);
            dest.writeParcelable(this.loopTimeItemBean, flags);
            dest.writeParcelable(this.loopIntervalItemBean, flags);
        }

        public void readFromParcel(Parcel source) {
            this.protocolType = source.readInt();
            this.loopType = source.readInt();
            this.loopCountItemBean = source.readParcelable(ModeSettingItemBean.class.getClassLoader());
            this.loopTimeItemBean = source.readParcelable(ModeSettingItemBean.class.getClassLoader());
            this.loopIntervalItemBean = source.readParcelable(ModeSettingItemBean.class.getClassLoader());
        }

        public ModeSettingLoopBean() {
        }

        protected ModeSettingLoopBean(Parcel in) {
            this.protocolType = in.readInt();
            this.loopType = in.readInt();
            this.loopCountItemBean = in.readParcelable(ModeSettingItemBean.class.getClassLoader());
            this.loopTimeItemBean = in.readParcelable(ModeSettingItemBean.class.getClassLoader());
            this.loopIntervalItemBean = in.readParcelable(ModeSettingItemBean.class.getClassLoader());
        }

        public static final Creator<ModeSettingLoopBean> CREATOR = new Creator<ModeSettingLoopBean>() {
            @Override
            public ModeSettingLoopBean createFromParcel(Parcel source) {
                return new ModeSettingLoopBean(source);
            }

            @Override
            public ModeSettingLoopBean[] newArray(int size) {
                return new ModeSettingLoopBean[size];
            }
        };
    }
    //endregion


    //region ModeSettingStepBean
    public static class ModeSettingStepBean {
        private int protocolType; //协议的类型，根据模型返回值来确定 0.未知  1.超8的协议  2.双鱼自研（目前用于超6）

        //mark 只有基本模式会有循环的参数
        int loopType;   //0.训练循环次数  1.训练时长
        private ModeSettingItemBean loopCountItemBean;    //训练循环次数
        private ModeSettingItemBean loopTimeItemBean;     //训练时长
        private ModeSettingItemBean loopIntervalItemBean; //训练循环间隔

        //单球次数 基本模式没有单球次数(有循环参数）其他模式都有该参数
        private ModeSettingItemBean countItemBean;        //单球次数
        //mark 以下参数为所有模式共有
        private ModeSettingItemBean frequencyItemBean;    //发球频率
        private ModeSettingItemBean speedItemBean;        //发球速度

        private int rotationType;  //0.不旋  1上旋  2下旋
        private ModeSettingItemBean upRotationItemBean;   //上旋球
        private ModeSettingItemBean downRotationItemBean; //下旋球
        private ModeSettingItemBean noRotationItemBean;   //不旋球

        private ModeSettingItemBean horizontalItemBean;   //落点角度（水平方向）
        private ModeSettingItemBean verticalItemBean;     //弧线角度 (垂直方向)
        private ModeSettingItemBean degreeItemBean;       //侧旋角度调整

        public int getLoopType() {
            return loopType;
        }

        public void setLoopType(int loopType) {
            this.loopType = loopType;
        }

        public ModeSettingItemBean getLoopCountItemBean() {
            return loopCountItemBean;
        }

        public void setLoopCountItemBean(ModeSettingItemBean loopCountItemBean) {
            this.loopCountItemBean = loopCountItemBean;
        }

        public ModeSettingItemBean getLoopTimeItemBean() {
            return loopTimeItemBean;
        }

        public void setLoopTimeItemBean(ModeSettingItemBean loopTimeItemBean) {
            this.loopTimeItemBean = loopTimeItemBean;
        }

        public ModeSettingItemBean getLoopIntervalItemBean() {
            return loopIntervalItemBean;
        }

        public void setLoopIntervalItemBean(ModeSettingItemBean loopIntervalItemBean) {
            this.loopIntervalItemBean = loopIntervalItemBean;
        }

        public ModeSettingItemBean getCountItemBean() {
            return countItemBean;
        }

        public void setCountItemBean(ModeSettingItemBean countItemBean) {
            this.countItemBean = countItemBean;
        }

        public ModeSettingItemBean getFrequencyItemBean() {
            return frequencyItemBean;
        }

        public void setFrequencyItemBean(ModeSettingItemBean frequencyItemBean) {
            this.frequencyItemBean = frequencyItemBean;
        }

        public ModeSettingItemBean getSpeedItemBean() {
            return speedItemBean;
        }

        public void setSpeedItemBean(ModeSettingItemBean speedItemBean) {
            this.speedItemBean = speedItemBean;
        }

        public int getRotationType() {
            return rotationType;
        }

        public void setRotationType(int rotationType) {
            this.rotationType = rotationType;
        }

        public ModeSettingItemBean getUpRotationItemBean() {
            return upRotationItemBean;
        }

        public void setUpRotationItemBean(ModeSettingItemBean upRotationItemBean) {
            this.upRotationItemBean = upRotationItemBean;
        }

        public ModeSettingItemBean getDownRotationItemBean() {
            return downRotationItemBean;
        }

        public void setDownRotationItemBean(ModeSettingItemBean downRotationItemBean) {
            this.downRotationItemBean = downRotationItemBean;
        }

        public ModeSettingItemBean getNoRotationItemBean() {
            return noRotationItemBean;
        }

        public void setNoRotationItemBean(ModeSettingItemBean noRotationItemBean) {
            this.noRotationItemBean = noRotationItemBean;
        }

        public ModeSettingItemBean getHorizontalItemBean() {
            return horizontalItemBean;
        }

        public void setHorizontalItemBean(ModeSettingItemBean horizontalItemBean) {
            this.horizontalItemBean = horizontalItemBean;
        }

        public ModeSettingItemBean getVerticalItemBean() {
            return verticalItemBean;
        }

        public void setVerticalItemBean(ModeSettingItemBean verticalItemBean) {
            this.verticalItemBean = verticalItemBean;
        }

        public ModeSettingItemBean getDegreeItemBean() {
            return degreeItemBean;
        }

        public void setDegreeItemBean(ModeSettingItemBean degreeItemBean) {
            this.degreeItemBean = degreeItemBean;
        }

        public int getProtocolType() {
            return protocolType;
        }

        public void setProtocolType(int protocolType) {
            this.protocolType = protocolType;
        }

        //mark- 发球脚本相关
        //生成发球脚本
        public String makeScript() {
            if ((protocolType != ModeConstant.ProtocolTypeS5)
                    && (protocolType != ModeConstant.ProtocolTypeS6)
                    && (protocolType != ModeConstant.ProtocolTypeS8)) {
                return "";
            }

            StringBuilder builder = new StringBuilder();

            //超5
            if (protocolType == ModeConstant.ProtocolTypeS5) {
                //		0,0,3,3,6#
                if (rotationType == 1) {
                    builder.append("1,").append(upRotationItemBean.getCurrentValue());
                } else if (rotationType == 2) {
                    builder.append("2,").append(downRotationItemBean.getCurrentValue());
                } else {
                    builder.append("0,0");
                }
                builder.append(",");
                builder.append(speedItemBean.currentValue);
                builder.append(",");
                builder.append(frequencyItemBean.currentValue);
                builder.append(",");
                builder.append(horizontalItemBean.currentValue);
                builder.append("#");

                return builder.toString();
            }

            //超6 超8
            //单球次数
            if (countItemBean == null) {
                //基本模式
                builder.append("0,1,#");
            } else {
                if (countItemBean.isChooseRange()) {
                    builder.append("1,").append(countItemBean.currentMinValue)
                            .append("-").append(countItemBean.currentMaxValue).append(",#");
                } else {
                    builder.append("0,").append(countItemBean.currentValue).append(",#");
                }
            }

            //发球频率
            if (frequencyItemBean == null) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    builder.append("0,40,#");
                } else if (protocolType == ModeConstant.ProtocolTypeS6) {
                    builder.append("0,4,#");
                }
            } else {
                if (frequencyItemBean.isChooseRange()) {
                    builder.append("1,").append(frequencyItemBean.currentMinValue)
                            .append("-").append(frequencyItemBean.currentMaxValue).append(",#");
                } else {
                    builder.append("0,").append(frequencyItemBean.currentValue).append(",#");
                }
            }

            //发球速度
            if (speedItemBean == null) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    builder.append("0,17,#");
                } else if (protocolType == ModeConstant.ProtocolTypeS6) {
                    builder.append("0,4,#");
                }
            } else {
                if (speedItemBean.isChooseRange()) {
                    builder.append("1,").append(speedItemBean.currentMinValue)
                            .append("-").append(speedItemBean.currentMaxValue).append(",#");
                } else {
                    builder.append("0,").append(speedItemBean.currentValue).append(",#");
                }
            }

            //旋转球
            if (rotationType == 1) {
                //上旋球
                if (upRotationItemBean == null) {
                    if (protocolType == ModeConstant.ProtocolTypeS8) {
                        builder.append("0,25,#");
                    } else if  (protocolType == ModeConstant.ProtocolTypeS6) {
                        builder.append("0,20,#");
                    }
                } else {
                    int offset = 0;
                    if (protocolType == ModeConstant.ProtocolTypeS8) {
                        offset = 25;
                    } else if  (protocolType == ModeConstant.ProtocolTypeS6) {
                        offset = 20;
                    }
                    if (upRotationItemBean.isChooseRange()) {
                        builder.append("1,").append(upRotationItemBean.currentMinValue + offset)
                                .append("-").append(upRotationItemBean.currentMaxValue + offset).append(",#");
                    } else {
                        builder.append("0,").append(upRotationItemBean.currentValue + offset).append(",#");
                    }
                }
            } else if (rotationType == 2) {
                //下旋球
                if (downRotationItemBean == null) {
                    if (protocolType == ModeConstant.ProtocolTypeS8) {
                        builder.append("0,25,#");
                    } else if  (protocolType == ModeConstant.ProtocolTypeS6) {
                        builder.append("0,20,#");
                    }
                } else {
                    if (downRotationItemBean.isChooseRange()) {
                        //0~24下旋  界面显示为 1-25
                        //用的25-value  所以value的最大最小值要 倒一下
                        if (protocolType == ModeConstant.ProtocolTypeS8) {
                            builder.append("1,").append(25 - downRotationItemBean.currentMaxValue)
                                    .append("-").append(25 - downRotationItemBean.currentMinValue).append(",#");
                        } else if  (protocolType == ModeConstant.ProtocolTypeS6) {
                            //0~19下旋  界面显示为 1-20
                            //用的25-value  所以value的最大最小值要 倒一下
                            builder.append("1,").append(20 - downRotationItemBean.currentMaxValue)
                                    .append("-").append(20 - downRotationItemBean.currentMinValue).append(",#");
                        }
                    } else {
                        if (protocolType == ModeConstant.ProtocolTypeS8) {
                            builder.append("0,").append(25 - downRotationItemBean.currentValue).append(",#");
                        } else if  (protocolType == ModeConstant.ProtocolTypeS6) {
                            builder.append("0,").append(20 - downRotationItemBean.currentValue).append(",#");
                        }
                    }
                }
            } else {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    builder.append("0,25,#");
                } else if  (protocolType == ModeConstant.ProtocolTypeS6) {
                    builder.append("0,20,#");
                }
            }

            //落点角度
            if (horizontalItemBean == null) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    builder.append("0,40,#");
                } else if (protocolType == ModeConstant.ProtocolTypeS6) {
                    builder.append("0,9,#");
                }
            } else {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    if (horizontalItemBean.isChooseRange()) {
                        builder.append("1,").append(horizontalItemBean.currentMinValue)
                                .append("-").append(horizontalItemBean.currentMaxValue).append(",#");
                    } else {
                        builder.append("0,").append(horizontalItemBean.currentValue).append(",#");
                    }
                } else if (protocolType == ModeConstant.ProtocolTypeS6) {
                    if (horizontalItemBean.isChooseRange()) {
                        builder.append("1,").append(horizontalItemBean.currentMinValue + 9)
                                .append("-").append(horizontalItemBean.currentMaxValue + 9).append(",#");
                    } else {
                        builder.append("0,").append(horizontalItemBean.currentValue + 9).append(",#");
                    }
                }
            }

            //弧线角度
            if (verticalItemBean == null) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    builder.append("0,25,#");
                } else if (protocolType == ModeConstant.ProtocolTypeS6) {
                    builder.append("0,15,#");
                }
            } else {
                if (verticalItemBean.isChooseRange()) {
                    builder.append("1,").append(verticalItemBean.currentMinValue)
                            .append("-").append(verticalItemBean.currentMaxValue).append(",#");
                } else {
                    builder.append("0,").append(verticalItemBean.currentValue).append(",#");
                }
            }

            //侧旋角度调整
            if (degreeItemBean == null) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    builder.append("0,90,#");
                } else if (protocolType == ModeConstant.ProtocolTypeS6) {
                    builder.append("0,8,#");
                }
            } else {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    if (degreeItemBean.isChooseRange()) {
                        builder.append("1,").append(degreeItemBean.currentMinValue + 90)
                                .append("-").append(degreeItemBean.currentMaxValue + 90).append(",#");
                    } else {
                        builder.append("0,").append(degreeItemBean.currentValue + 90).append(",#");
                    }
                } else if (protocolType == ModeConstant.ProtocolTypeS6) {
                    if (degreeItemBean.isChooseRange()) {
                        builder.append("1,").append(degreeItemBean.currentMinValue + 8)
                                .append("-").append(degreeItemBean.currentMaxValue + 8).append(",#");
                    } else {
                        builder.append("0,").append(degreeItemBean.currentValue + 8).append(",#");
                    }
                }
            }

            builder.append("\n");
            return builder.toString();
        }

        public static ModeSettingStepBean createDefaultSettingStepBean(int protocolType) {
            String script = "";
            if (protocolType == ModeConstant.ProtocolTypeS8) {
                script = "0,1,#0,20,#0,40,#0,25,#0,25,#0,19,#0,90";
            } else if (protocolType == ModeConstant.ProtocolTypeS6) {
                script = "0,1,#0,40,#0,10,#0,20,#0,9,#0,15,#0,8";
            } else if (protocolType == ModeConstant.ProtocolTypeS5) {
                script = "0,0,3,3,6";
            }
            return createSettingStepBean(script, protocolType);
        }

        public static ModeSettingStepBean createSettingStepBean(String script, int protocolType) {
            if (protocolType == ModeConstant.ProtocolTypeS5) {
                return createS5SettingStepBean(script);
            } else if (protocolType == ModeConstant.ProtocolTypeS6) {
                return createS6SettingStepBean(script);
            } else if (protocolType == ModeConstant.ProtocolTypeS8) {
                return createS8SettingStepBean(script);
            }
            return null;
        }

        private static ModeSettingStepBean createS5SettingStepBean(String script) {
            //将脚本继续分解，提取出各个发球参数项
            String[] params = script.split(",");
            if (params.length < 5) {
                //发球参数项为5个
                return null;
            }

            Context context = AppCacheUtil.getInstance().getAppContext();
            //初始化各个item模型，并赋初始值
            ModeSettingItemBean frequencyItemBean = new ModeSettingItemBean(context.getString(R.string.frequency), false, false, 9, 1, 3, 9, 1);
            ModeSettingItemBean speedItemBean = new ModeSettingItemBean(context.getString(R.string.speed), false, false, 9, 1, 3, 9, 1);
            ModeSettingItemBean noRotationItemBean = new ModeSettingItemBean(context.getString(R.string.non_spin), false, false, 0, 0, 0, 0, 0);
            ModeSettingItemBean upRotationItemBean = new ModeSettingItemBean(context.getString(R.string.top_spin), false, false, 9, 1, 3, 9, 1);
            ModeSettingItemBean downRotationItemBean = new ModeSettingItemBean(context.getString(R.string.back_spin), false, false, 9, 1, 3, 9, 1);
            ModeSettingItemBean horizontalItemBean = new ModeSettingItemBean(context.getString(R.string.horizontal), false, false, 12, 0, 6, 12, 0);

            int protocolType = ModeConstant.ProtocolTypeS5;
            frequencyItemBean.setProtocolType(protocolType);
            speedItemBean.setProtocolType(protocolType);
            noRotationItemBean.setProtocolType(protocolType);
            upRotationItemBean.setProtocolType(protocolType);
            downRotationItemBean.setProtocolType(protocolType);
            horizontalItemBean.setProtocolType(protocolType);

            //mark - MARk://按顺序取值 为item赋值
            //	脚本格式
            //	目前暂定为：0,0,3,3,6#
            //	第0位：旋转方式    0:不旋 1:上旋 2:下旋
            //	第1位：旋转强度
            //	第2位：发球速度
            //	第3位：发球频率
            //	第4位：落点角度
            int rotationType = parseToInt(params[0]);
            int rotationValue = parseToInt(params[1]);
            if (rotationType == 0) {
                noRotationItemBean.setCurrentValue(rotationValue);
            } else if (rotationType == 1) {
                upRotationItemBean.setCurrentValue(rotationValue);
            } else if (rotationType == 2) {
                downRotationItemBean.setCurrentValue(rotationValue);
            }
            //发球速度
            int speed = parseToInt(params[2]);
            speedItemBean.setCurrentValue(speed);
            //发球频率
            int frequency = parseToInt(params[3]);
            frequencyItemBean.setCurrentValue(frequency);
            //落点角度
            int landingPoint = parseToInt(params[4]);
            horizontalItemBean.setCurrentValue(landingPoint);

            //ModeSettingStepBean
            ModeSettingStepBean stepBean = new ModeSettingStepBean();
            stepBean.setProtocolType(protocolType);
            stepBean.setFrequencyItemBean(frequencyItemBean);
            stepBean.setSpeedItemBean(speedItemBean);
            stepBean.setHorizontalItemBean(horizontalItemBean);

            stepBean.setRotationType(rotationType);
            stepBean.setNoRotationItemBean(noRotationItemBean);
            stepBean.setUpRotationItemBean(upRotationItemBean);
            stepBean.setDownRotationItemBean(downRotationItemBean);

            return stepBean;
        }

        private static ModeSettingStepBean createS6SettingStepBean(String script) {

            //将脚本继续分解，提取出各个发球参数项
            String[] params = parseStepScript(script);
            if (params.length < 7) {
                //发球参数项为7个
                return null;
            }

            Context context = AppCacheUtil.getInstance().getAppContext();
            //初始化各个item模型，并赋初始值
            ModeSettingItemBean countItemBean = new ModeSettingItemBean(context.getString(R.string.number), true, false, 100, 1, 1, 100, 1);
            ModeSettingItemBean frequencyItemBean = new ModeSettingItemBean(context.getString(R.string.frequency), true, false, 85, 20, 40, 20, 85);
            ModeSettingItemBean speedItemBean = new ModeSettingItemBean(context.getString(R.string.speed), true, false, 20, 1, 4, 20, 1);

            ModeSettingItemBean noRotationItemBean = new ModeSettingItemBean(context.getString(R.string.non_spin), false, false, 0, 0, 0, 0, 0);
            ModeSettingItemBean upRotationItemBean = new ModeSettingItemBean(context.getString(R.string.top_spin), true, false, 20, 1, 6, 20, 1);
            ModeSettingItemBean downRotationItemBean = new ModeSettingItemBean(context.getString(R.string.back_spin), true, false, 20, 1, 6, 20, 1);

            ModeSettingItemBean horizontalItemBean = new ModeSettingItemBean(context.getString(R.string.horizontal), true, false, 9, -9, 0, 9, -9);
            ModeSettingItemBean verticalItemBean = new ModeSettingItemBean(context.getString(R.string.elevation), true, false, 30, 0, 15, 30, 0);
            ModeSettingItemBean degreeItemBean = new ModeSettingItemBean(context.getString(R.string.sidespin), true, false, 8, -8, 0, 8, -8);

            int protocolType = ModeConstant.ProtocolTypeS6;
            countItemBean.setProtocolType(protocolType);
            frequencyItemBean.setProtocolType(protocolType);
            speedItemBean.setProtocolType(protocolType);
            noRotationItemBean.setProtocolType(protocolType);
            upRotationItemBean.setProtocolType(protocolType);
            downRotationItemBean.setProtocolType(protocolType);

            horizontalItemBean.setProtocolType(protocolType);
            verticalItemBean.setProtocolType(protocolType);
            degreeItemBean.setProtocolType(protocolType);

            //mark - MARk://按顺序取值 为item赋值
            //发球次数 （协议中范围为1-9999） 实际取值范围1-100
            String param = params[0];
            String[] values = analyseParam(param);
            setItemBean(countItemBean, values);

            //发球频率 取值范围20-85
            param = params[1];
            values = analyseParam(param);
            setItemBean(frequencyItemBean, values);

            //发球速度  取值范围1-20
            param = params[2];
            values = analyseParam(param);
            setItemBean(speedItemBean, values);

            //旋球强度：-20 ~ 20
            param = params[3];
            values = analyseParam(param);
            int rotationType = setS6RotaitionItemBean(noRotationItemBean, upRotationItemBean, downRotationItemBean, values);

            //落点角度（水平方向）
            param = params[4];
            values = analyseParam(param);
            setS6LandItemBean(horizontalItemBean, values);

            //弧线角度 (垂直方向)
            param = params[5];
            values = analyseParam(param);
            setItemBean(verticalItemBean, values);

            //侧旋角度调整
            //侧旋角度：0-16   0~7左旋逆时针 8正中间 9~16右旋顺时针  (界面上显示为 -8 ~ 8)
            param = params[6];
            values = analyseParam(param);
            setS6DegreeItemBean(degreeItemBean, values);

            ModeSettingStepBean stepBean = new ModeSettingStepBean();
            stepBean.setProtocolType(protocolType);
            stepBean.setCountItemBean(countItemBean);
            stepBean.setFrequencyItemBean(frequencyItemBean);
            stepBean.setSpeedItemBean(speedItemBean);

            stepBean.setRotationType(rotationType);
            stepBean.setNoRotationItemBean(noRotationItemBean);
            stepBean.setUpRotationItemBean(upRotationItemBean);
            stepBean.setDownRotationItemBean(downRotationItemBean);

            stepBean.setHorizontalItemBean(horizontalItemBean);
            stepBean.setVerticalItemBean(verticalItemBean);
            stepBean.setDegreeItemBean(degreeItemBean);

            return stepBean;
        }

        private static ModeSettingStepBean createS8SettingStepBean(String script) {

            //将脚本继续分解，提取出各个发球参数项
            String[] params = parseStepScript(script);
            if (params.length < 7) {
                //发球参数项为7个
                return null;
            }
            Context context = AppCacheUtil.getInstance().getAppContext();
            //初始化各个item模型，并赋初始值
            ModeSettingItemBean countItemBean = new ModeSettingItemBean(context.getString(R.string.number), true, false, 100, 1, 1, 100, 1);
            ModeSettingItemBean frequencyItemBean = new ModeSettingItemBean(context.getString(R.string.frequency), true, false, 100, 1, 40, 100, 1);
            ModeSettingItemBean speedItemBean = new ModeSettingItemBean(context.getString(R.string.speed), true, false, 100, 1, 17, 100, 1);

            ModeSettingItemBean noRotationItemBean = new ModeSettingItemBean(context.getString(R.string.non_spin), false, false, 0, 0, 0, 0, 0);
            ModeSettingItemBean upRotationItemBean = new ModeSettingItemBean(context.getString(R.string.top_spin), true, false, 25, 1, 9, 25, 1);
            ModeSettingItemBean downRotationItemBean = new ModeSettingItemBean(context.getString(R.string.back_spin), true, false, 25, 1, 9, 25, 1);

            ModeSettingItemBean horizontalItemBean = new ModeSettingItemBean(context.getString(R.string.horizontal), true, false, 50, 0, 25, 50, 0);
            ModeSettingItemBean verticalItemBean = new ModeSettingItemBean(context.getString(R.string.elevation), true, false, 50, 0, 25, 50, 0);
            ModeSettingItemBean degreeItemBean = new ModeSettingItemBean(context.getString(R.string.sidespin), true, false, 90, -90, 0, 90, -90);

            int protocolType = ModeConstant.ProtocolTypeS8;
            countItemBean.setProtocolType(protocolType);
            frequencyItemBean.setProtocolType(protocolType);
            speedItemBean.setProtocolType(protocolType);
            noRotationItemBean.setProtocolType(protocolType);
            upRotationItemBean.setProtocolType(protocolType);
            downRotationItemBean.setProtocolType(protocolType);
            horizontalItemBean.setProtocolType(protocolType);
            verticalItemBean.setProtocolType(protocolType);
            degreeItemBean.setProtocolType(protocolType);

            //mark - MARk://按顺序取值 为item赋值
            //发球次数 （协议中范围为1-9999） 实际取值范围1-100
            String param = params[0];
            String[] values = analyseParam(param);
            setItemBean(countItemBean, values);

            //发球频率 取值范围1-100
            param = params[1];
            values = analyseParam(param);
            setItemBean(frequencyItemBean, values);

            //发球速度  球速，在4~14m/s中取100等份。 取值范围1-100
            param = params[2];
            values = analyseParam(param);
            setItemBean(speedItemBean, values);

            //旋球强度：0~24下旋 25不旋 26~50上旋 (界面显示为1-25)
            param = params[3];
            values = analyseParam(param);
            int rotationType = setS8RotaitionItemBean(noRotationItemBean, upRotationItemBean, downRotationItemBean, values);

            //落点角度（水平方向）
            param = params[4];
            values = analyseParam(param);
            setItemBean(horizontalItemBean, values);

            //弧线角度 (垂直方向)
            param = params[5];
            values = analyseParam(param);
            setItemBean(verticalItemBean, values);

            //侧旋角度调整
            //侧旋角度：0~89左旋 90正中间 91~180右旋  (界面上显示为 -90 ~ 90)
            param = params[6];
            values = analyseParam(param);
            setS8DegreeItemBean(degreeItemBean, values);

            ModeSettingStepBean stepBean = new ModeSettingStepBean();
            stepBean.setProtocolType(protocolType);
            stepBean.setCountItemBean(countItemBean);
            stepBean.setFrequencyItemBean(frequencyItemBean);
            stepBean.setSpeedItemBean(speedItemBean);

            stepBean.setRotationType(rotationType);
            stepBean.setNoRotationItemBean(noRotationItemBean);
            stepBean.setUpRotationItemBean(upRotationItemBean);
            stepBean.setDownRotationItemBean(downRotationItemBean);

            stepBean.setHorizontalItemBean(horizontalItemBean);
            stepBean.setVerticalItemBean(verticalItemBean);
            stepBean.setDegreeItemBean(degreeItemBean);

            return stepBean;
        }

        //设置通用模型数据 （s8旋球 s8侧旋调整  s6旋转 s6落点 s6侧旋 要单独处理）
        private static void setItemBean(ModeSettingItemBean itemBean, String[] values) {
            if (values.length < 2) {
                return;
            }
            int rangeValue = parseToInt(values[0]);
            if (rangeValue == 0) {
                itemBean.setChooseRange(false);
                itemBean.setCurrentValue(parseToInt(values[1]));
            } else {
                if (values.length < 3) {
                    return;
                }
                itemBean.setChooseRange(true);
                itemBean.setCurrentMinValue(parseToInt(values[1]));
                itemBean.setCurrentMaxValue(parseToInt(values[2]));
            }
        }

        //s6 单独设置 弧线角度
        //旋球强度： 0-40  20不旋转，0-19下旋，21-40上旋  (界面上显示为 -20 ~ 20);
        private static int setS6RotaitionItemBean(ModeSettingItemBean noRotationItemBean, ModeSettingItemBean upRotationItemBean, ModeSettingItemBean downRotationItemBean, String[] values) {
            if (values.length < 2) {
                return 0;
            }
            int rangeValue = parseToInt(values[0]);
            int value1 = parseToInt(values[1]);
            int rotationType = 0;

            //固定取值
            if (rangeValue == 0) {
                if (value1 == 20) {
                    noRotationItemBean.setCurrentValue(0);
                } else if (value1 < 20) {
                    //下旋球
                    rotationType = 2;
                    downRotationItemBean.setCurrentValue(20 -value1);  //0~19下旋  界面显示为 1-20
                } else {
                    //上旋
                    rotationType = 1;
                    upRotationItemBean.setCurrentValue(value1 - 20);  // 21 ~ 40向上旋  界面显示为 1-20
                }
            } else {
                //范围取值
                if (values.length < 3) {
                    return 0;
                }
                int value2 = parseToInt(values[2]);
                if (value1 == 20) {
                    //不旋球
                    noRotationItemBean.setCurrentValue(0);
                } else if (value1 < 20) {
                    //下旋球
                    rotationType = 2;
                    downRotationItemBean.setChooseRange(true);
                    //0~19下旋  界面显示为 1-20
                    //用的20-value  所以value的最大最小值要 倒一下
                    downRotationItemBean.setCurrentMinValue(20 - value2);
                    downRotationItemBean.setCurrentMaxValue(20 - value1);
                } else {
                    //上旋球
                    rotationType = 1;
                    upRotationItemBean.setChooseRange(true);
                    upRotationItemBean.setCurrentMinValue(value1 - 20);   // 21 ~ 40向上旋  界面显示为 1-20
                    upRotationItemBean.setCurrentMaxValue(value2 - 20);
                }
            }
            return rotationType;
        }

        //单独设置 s6落点
        //落点：0~8左边 9正中间 10~18右边  (界面上显示为 -9 ~ 9)
        private static void setS6LandItemBean(ModeSettingItemBean landItemBean, String[] values) {
            if (values.length < 2) {
                return;
            }
            int rangeValue = parseToInt(values[0]);
            int value1 = parseToInt(values[1]);
            //固定取值
            if (rangeValue == 0) {
                landItemBean.setChooseRange(false);
                landItemBean.setCurrentValue(value1 - 9);

            } else {
                //范围取值
                if (values.length < 3) {
                    return;
                }
                int value2 = parseToInt(values[2]);
                landItemBean.setChooseRange(true);
                landItemBean.setCurrentMinValue(value1 - 9);
                landItemBean.setCurrentMaxValue(value2 - 9);
            }
        }

        //侧旋角度调整
        //侧旋角度：0-16   0~7左旋逆时针 8正中间 9~16右旋顺时针  (界面上显示为 -8 ~ 8)
        private static void setS6DegreeItemBean(ModeSettingItemBean itemBean, String[] values) {
            if (values.length < 2) {
                return;
            }
            int rangeValue = parseToInt(values[0]);
            if (rangeValue == 0) {
                itemBean.setChooseRange(false);
                itemBean.setCurrentValue(parseToInt(values[1]) - 8);
            } else {
                if (values.length < 3) {
                    return;
                }
                itemBean.setChooseRange(true);
                itemBean.setCurrentMinValue(parseToInt(values[1]) - 8);
                itemBean.setCurrentMaxValue(parseToInt(values[2]) - 8);
            }
        }

        //s8 单独设置 弧线角度
        //旋球强度：0~24下旋 25不旋 26 ~ 50向上
        private static int setS8RotaitionItemBean(ModeSettingItemBean noRotationItemBean, ModeSettingItemBean upRotationItemBean, ModeSettingItemBean downRotationItemBean, String[] values) {
            if (values.length < 2) {
                return 0;
            }
            int rangeValue = parseToInt(values[0]);
            int value1 = parseToInt(values[1]);
            int rotationType = 0;

            //固定取值
            if (rangeValue == 0) {
                if (value1 == 25) {
                    noRotationItemBean.setCurrentValue(0);
                } else if (value1 < 25) {
                    //下旋球
                    rotationType = 2;
                    downRotationItemBean.setCurrentValue(25 - value1);  //0~24下旋  界面显示为 1-25
                } else {
                    //上旋
                    rotationType = 1;
                    upRotationItemBean.setCurrentValue(value1 - 25);  // 26 ~ 50向上旋  界面显示为 1-25
                }
            } else {
                //范围取值
                if (values.length < 3) {
                    return 0;
                }
                int value2 = parseToInt(values[2]);
                if (value1 == 25) {
                    //不旋球
                    noRotationItemBean.setCurrentValue(0);
                } else if (value1 < 25) {
                    //下旋球
                    rotationType = 2;
                    downRotationItemBean.setChooseRange(true);
                    //0~24下旋  界面显示为 1-25
                    //用的25-value  所以value的最大最小值要 倒一下
                    downRotationItemBean.setCurrentMinValue(25 - value2);  //0~24下旋  界面显示为 1-25
                    downRotationItemBean.setCurrentMaxValue(25 - value1);  //0~24下旋  界面显示为 1-25
                } else {
                    //上旋球
                    rotationType = 1;
                    upRotationItemBean.setChooseRange(true);
                    upRotationItemBean.setCurrentMinValue(value1 - 25);   // 26 ~ 50向上旋  界面显示为 1-25
                    upRotationItemBean.setCurrentMaxValue(value2 - 25);  // 26 ~ 50向上旋  界面显示为 1-25
                }
            }
            return rotationType;
        }

        //单独设置 侧旋调整
        //侧旋角度：0~89左旋 90正中间 91~180右旋  (界面上显示为 -90 ~ 90)
        private static void setS8DegreeItemBean(ModeSettingItemBean itemBean, String[] values) {
            if (values.length < 2) {
                return;
            }
            int rangeValue = parseToInt(values[0]);
            if (rangeValue == 0) {
                itemBean.setChooseRange(false);
                itemBean.setCurrentValue(parseToInt(values[1]) - 90);
            } else {
                if (values.length < 3) {
                    return;
                }
                itemBean.setChooseRange(true);
                itemBean.setCurrentMinValue(parseToInt(values[1]) - 90);
                itemBean.setCurrentMaxValue(parseToInt(values[2]) - 90);
            }
        }

        private static int parseToInt(String number) {
            int num = 0;
            try {
                num = Integer.parseInt(number);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
            return num;
        }

        //将脚本继续分解，提取出各个发球参数项
        private static String[] parseStepScript(String step) {
            if (step == null || step.length() == 0) {
                return null;
            }
            return step.split(",#");
        }

        //解析单个参数
        private static String[] analyseParam(String param) {
            if (param == null || param.length() == 0) {
                return null;
            }
            return param.split(",|-");
        }
    }

    //endregion

    //region ModeSettingItemBean
    public static class ModeSettingItemBean implements Parcelable {

        private int protocolType; //协议的类型，根据模型返回值来确定 0.未知  1.超8的协议  2.双鱼自研（目前用于超6） 3.超5

        private String name;

        private boolean canChooseRange;  //是否可选择范围 默认 YES
        private boolean isChooseRange;  //是否选择范围 默认 NO 固定值

        private int maxValue;   //最大值
        private int minValue;   //最小值

        private int currentValue;     //当前值
        private int currentMaxValue;  //当前最大值
        private int currentMinValue;  //当前最小值

        /***  超5 内置模式特有的属性 ***/
        //是否是固定的值，固定值不允许修改
        private boolean isConstant = false;
        private String constantValue;

        public ModeSettingItemBean(String name, boolean canChooseRange, boolean isChooseRange, int maxValue, int minValue, int currentValue, int currentMaxValue, int currentMinValue) {

            this.name = name;
            this.canChooseRange = canChooseRange;
            this.isChooseRange = isChooseRange;

            this.maxValue = maxValue;
            this.minValue = minValue;
            this.currentValue = currentValue;
            this.currentMaxValue = currentMaxValue;
            this.currentMinValue = currentMinValue;
        }

        public int getProtocolType() {
            return protocolType;
        }

        public void setProtocolType(int protocolType) {
            this.protocolType = protocolType;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public boolean isCanChooseRange() {
            return canChooseRange;
        }

        public void setCanChooseRange(boolean canChooseRange) {
            this.canChooseRange = canChooseRange;
        }

        public boolean isChooseRange() {
            return isChooseRange;
        }

        public void setChooseRange(boolean chooseRange) {
            isChooseRange = chooseRange;
        }

        public int getMaxValue() {
            return maxValue;
        }

        public void setMaxValue(int maxValue) {
            this.maxValue = maxValue;
        }

        public int getMinValue() {
            return minValue;
        }

        public void setMinValue(int minValue) {
            this.minValue = minValue;
        }

        public int getCurrentValue() {
            return currentValue;
        }

        public void setCurrentValue(int currentValue) {
            this.currentValue = currentValue;
        }

        public int getCurrentMaxValue() {
            return currentMaxValue;
        }

        public void setCurrentMaxValue(int currentMaxValue) {
            this.currentMaxValue = currentMaxValue;
        }

        public int getCurrentMinValue() {
            return currentMinValue;
        }

        public void setCurrentMinValue(int currentMinValue) {
            this.currentMinValue = currentMinValue;
        }

        public boolean isConstant() {
            return isConstant;
        }

        public void setConstant(boolean constant) {
            isConstant = constant;
        }

        public String getConstantValue() {
            return constantValue;
        }

        public void setConstantValue(String constantValue) {
            this.constantValue = constantValue;
        }

        //获取说明
        public String getDescWithItemTag(ModeSettingItemTag itemTag) {
            if (itemTag == ModeSettingItemTag.ModeSettingItemTagUnknown) {
                return null;
            }

            Context context = AppCacheUtil.getInstance().getAppContext();
            //超5
            if (protocolType == ModeConstant.ProtocolTypeS5) {
                if (itemTag == ModeSettingItemTag.ModeSettingItemTagFrequency) {
                    return context.getString(R.string.mode_desc_1_9);
                }
                if (itemTag == ModeSettingItemTag.ModeSettingItemTagSpeed) {
                    return context.getString(R.string.mode_desc_1_9);
                }
                if (itemTag == ModeSettingItemTag.ModeSettingItemTagNoRotation) {
                    return context.getString(R.string.mode_desc_0_0);
                }
                if (itemTag == ModeSettingItemTag.ModeSettingItemTagUpRotation) {
                    return context.getString(R.string.mode_desc_1_9);
                }
                if (itemTag == ModeSettingItemTag.ModeSettingItemTagDownRotation) {
                    return context.getString(R.string.mode_desc_1_9);
                }
                if (itemTag == ModeSettingItemTag.ModeSettingItemTagHorizontal) {
                    return context.getString(R.string.mode_desc_0_12);
                }
                return null;
            }

            //超6 超8 根据协议的不同，返回的内容也不同
            if (itemTag == ModeSettingItemTag.ModeSettingItemTagLoopTime) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
//                    return "取值范围：1 ~ 1440\n发球时长,单位为'分'";
                    return String.format(context.getString(R.string.mode_desc_1_n), 1440);
                }
                if (protocolType == ModeConstant.ProtocolTypeS6) {
//                    return "取值范围：1 ~ 120\n发球时长,单位为'分'";
                    return String.format(context.getString(R.string.mode_desc_1_n), 120);
                }
            }
            if (itemTag == ModeSettingItemTag.ModeSettingItemTagLoopCount) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
//                    return "取值范围：1 ~ 200\n";
                    return String.format(context.getString(R.string.mode_desc_1_n_2), 200);
                }
                if (protocolType == ModeConstant.ProtocolTypeS6) {
//                    return "取值范围：1 ~ 100\n";
                    return String.format(context.getString(R.string.mode_desc_1_n_2), 100);
                }
            }
            if (itemTag == ModeSettingItemTag.ModeSettingItemTagLoopInterval) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    return context.getString(R.string.mode_desc_1_20);
                }
                if (protocolType == ModeConstant.ProtocolTypeS6) {
                    return context.getString(R.string.mode_desc_1_10);
                }
            }
            if (itemTag == ModeSettingItemTag.ModeSettingItemTagSingleCount) {
                return context.getString(R.string.mode_desc_1_100);
            }
            if (itemTag == ModeSettingItemTag.ModeSettingItemTagFrequency) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    return context.getString(R.string.mode_desc_1_100_2);
                }
                if (protocolType == ModeConstant.ProtocolTypeS6) {
//                    return "取值范围：20 ~ " + maxValue +"\n一分钟发球个数";
                    return String.format(context.getString(R.string.mode_desc_20_n), maxValue);
                }
            }
            if (itemTag == ModeSettingItemTag.ModeSettingItemTagSpeed) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    return context.getString(R.string.mode_desc_1_100_3);
                }
                if (protocolType == ModeConstant.ProtocolTypeS6) {
                    return context.getString(R.string.mode_desc_1_20_2);
                }
            }
            if (itemTag == ModeSettingItemTag.ModeSettingItemTagNoRotation) {
                return context.getString(R.string.mode_desc_0_0);
            }
            if (itemTag == ModeSettingItemTag.ModeSettingItemTagUpRotation) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    return context.getString(R.string.mode_desc_1_25);
                }
                if (protocolType == ModeConstant.ProtocolTypeS6) {
                    return context.getString(R.string.mode_desc_1_20_3);
                }
            }
            if (itemTag == ModeSettingItemTag.ModeSettingItemTagDownRotation) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    return context.getString(R.string.mode_desc_1_25);
                }
                if (protocolType == ModeConstant.ProtocolTypeS6) {
                    return context.getString(R.string.mode_desc_1_20_3);
                }
            }
            if (itemTag == ModeSettingItemTag.ModeSettingItemTagHorizontal) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    return context.getString(R.string.mode_desc_0_50);
                }
                if (protocolType == ModeConstant.ProtocolTypeS6) {
                    return context.getString(R.string.mode_desc__9_9);
                }
            }
            if (itemTag == ModeSettingItemTag.ModeSettingItemTagVertical) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    return context.getString(R.string.mode_desc_0_50_2);
                }
                if (protocolType == ModeConstant.ProtocolTypeS6) {
                    return context.getString(R.string.mode_desc_0_30);
                }
            }
            if (itemTag == ModeSettingItemTag.ModeSettingItemTagDegree) {
                if (protocolType == ModeConstant.ProtocolTypeS8) {
                    return context.getString(R.string.mode_desc__90_90);
                }
                if (protocolType == ModeConstant.ProtocolTypeS6) {
                    return context.getString(R.string.mode_desc__8_8);
                }
            }
            return null;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(this.protocolType);
            dest.writeString(this.name);
            dest.writeByte(this.canChooseRange ? (byte) 1 : (byte) 0);
            dest.writeByte(this.isChooseRange ? (byte) 1 : (byte) 0);
            dest.writeInt(this.maxValue);
            dest.writeInt(this.minValue);
            dest.writeInt(this.currentValue);
            dest.writeInt(this.currentMaxValue);
            dest.writeInt(this.currentMinValue);
        }

        public void readFromParcel(Parcel source) {
            this.protocolType = source.readInt();
            this.name = source.readString();
            this.canChooseRange = source.readByte() != 0;
            this.isChooseRange = source.readByte() != 0;
            this.maxValue = source.readInt();
            this.minValue = source.readInt();
            this.currentValue = source.readInt();
            this.currentMaxValue = source.readInt();
            this.currentMinValue = source.readInt();
        }

        protected ModeSettingItemBean(Parcel in) {
            this.protocolType = in.readInt();
            this.name = in.readString();
            this.canChooseRange = in.readByte() != 0;
            this.isChooseRange = in.readByte() != 0;
            this.maxValue = in.readInt();
            this.minValue = in.readInt();
            this.currentValue = in.readInt();
            this.currentMaxValue = in.readInt();
            this.currentMinValue = in.readInt();
        }

        public static final Creator<ModeSettingItemBean> CREATOR = new Creator<ModeSettingItemBean>() {
            @Override
            public ModeSettingItemBean createFromParcel(Parcel source) {
                return new ModeSettingItemBean(source);
            }

            @Override
            public ModeSettingItemBean[] newArray(int size) {
                return new ModeSettingItemBean[size];
            }
        };
    }
    //endregion


    public enum ModeSettingItemTag {

        ModeSettingItemTagUnknown,                 //未知

        ModeSettingItemTagLoopTime,                //循环训练 时长
        ModeSettingItemTagLoopCount,               //循环训练 次数
        ModeSettingItemTagLoopInterval,            //循环训练间隔

        ModeSettingItemTagSingleCount,             //单球次数
        ModeSettingItemTagFrequency,               //发球频率
        ModeSettingItemTagSpeed,                   //发球速度
        ModeSettingItemTagNoRotation,              //不旋转球
        ModeSettingItemTagUpRotation,              //上旋转球
        ModeSettingItemTagDownRotation,            //下旋转球
        ModeSettingItemTagHorizontal,              //落点角度（水平方向）
        ModeSettingItemTagVertical,                //弧线角度 (垂直方向)
        ModeSettingItemTagDegree,                  //侧旋角度调整
        }
}
